// Copyright (c) 2013 The Wayixia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// A generic onclick callback function.
function genericOnClick(info, tab) {
  
  // alert(JSON.stringify(info));
  chrome.tabs.sendRequest(tab.id, {
    type : "create-dialog",
    img : {
      pageUrl:info.pageUrl, 
      srcUrl:info.srcUrl
    }
  });
}


// Create one test item for each context type. 
// "page","selection","editable","link","video","audio"

var contexts = ["image"];
for (var i = 0; i < contexts.length; i++) {
  var context = contexts[i];
  var title = "挖一下";
  var id = chrome.contextMenus.create({"title": title, "contexts":[context],
                                       "onclick": genericOnClick});
  console.log("'" + context + "' item:" + id);
}

// forward message to  listener of wayixa.js
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
  switch (request.type) {
    case "add-image":
      break;
    case "forward":
      chrome.tabs.sendRequest(sender.tab.id, request.request, sendResponse);
      break;
    default:
      sendResponse({});
      break;
  }
});